<?php
/**
 * Created by PhpStorm.
 * LICENSE: Apache 2.0
 * Date: 2019/3/8
 * Time: 上午1:10
 */

namespace app\portal\controller;


use app\portal\model\MessageModel;
use cmf\controller\AdminBaseController;
use think\Request;

class AdminMessageController extends AdminBaseController
{
    /**
     * @var MessageModel
     */
    protected $manager;
    public function index()
    {
        $this->manager = new MessageModel();
        $this->assign('messages',$this->manager->getList());
        return $this->fetch();
    }
    public function detail(Request $request){
        $id = $request->get('id');
        $this->manager = new MessageModel();
        $message = $this->manager->findOrFail($id);
        if($message['status']==0){
            $this->manager->where('id',$id)->update([
                'status'=>MessageModel::STATUS_READ
            ]);
            $message['status'] = MessageModel::STATUS_READ;
        }
        $this->assign('message',$message);
        return $this->fetch();
    }
    public function mark(Request $request){
        $id = $request->get('id');
        $this->manager = new MessageModel();
        $this->manager->where('id',$id)->update([
            'status'    =>  MessageModel::STATUS_MARK
        ]);
        $this->success('操作成功');
    }
}